    <link rel="stylesheet" href="/layui/css/layui.css">
    <script type="text/javascript" src="/layui/layui.js"></script>
    <script type="text/javascript" src="/layui/js/jquery.min.js"></script>
    <script type="text/javascript" src="/layui/jquery.cityselect.js"></script>
    <script type="text/javascript" src="/layui/city.min.js"></script>
    <script type="text/javascript" src="/layui/field.js"></script>
    <script type="text/javascript" src="/layui/comment.js"></script>
    <link rel="stylesheet" href="/layui/pinfen.css">
    <form class="layui-form" action="/admin/customer/{{$contacts->id}}" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">公司名</label>
            <div class="layui-input-block">
                <input type="text" name="company_name" lay-verify="title" value="{{$contacts->company_name}}" autocomplete="off" placeholder="请输入公司名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系人姓名</label>
            <div class="layui-input-block">
                <input type="text" name="contact_name" lay-verify="title" value="{{$contacts->name}}" autocomplete="off" placeholder="请输入联系人姓名" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-form-label">客户等级</div>
            <div id="rate-comm-1" value="1" name=customer_level class="rate-comm"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户状态：</label>
            <div class="layui-input-block">
                <select name="customer_type" lay-filter="source">
                    <option value="0" selected="">请选择一个客户状态</option>
                    <option value="1" >意向客户</option>
                    <option value="2">已成交客户</option>
                    <option value="3">失败客户</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">企业地址</label>
            <div class="layui-input-inline">
                <select name="prov" lay-filter="prov">
                    <option value="">请选择省</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="city" lay-filter="city" disabled>
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="dist" lay-filter="dist" disabled>
                    <option value="">请选择县/区</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">企业规模：</label>
            <div class="layui-input-block">
                <select name="customer_size" lay-filter="source">
                    <option value="0" selected="">请选择规模</option>
                    <option value="10人以下" >10人以下</option>
                    <option value="10人-50人">10人-50人</option>
                    <option value="100人-500人">100人-500人</option>
                    <option value="500人-1000人">500人-1000人</option>
                    <option value="1000人以上">1000人以上</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">下次联系时间</label>
            <div class="layui-input-inline">
                <input type="text" name="next_contact" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系周期：</label>
            <div class="layui-input-block">
                <select name="contact_cycle" lay-filter="source">
                    <option value="0" selected="">请选择一个联系周期</option>
                    <option value="1" >1天</option>
                    <option value="2" >3天</option>
                    <option value="3">5天</option>
                    <option value="4">7天</option>
                    <option value="5">15天</option>
                    <option value="6">30天</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">分配用户</label>
                <div class="layui-input-inline">
                    <select name="user_id">
                        <option value="">请选择问题</option>
                        <optgroup label="员工">
                            @foreach($users as $user)
                                <option value="{{$user->id}}">{{$user->name}}</option>
                            @endforeach
                        </optgroup>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>
    <script src="/js/address.js"></script>

    <script type="text/javascript">

        var areaData = address;
        var $form;
        var form;
        var $;
        $form = $('form');
        layui.use(['element','form','laydate'], function() {
            var table = layui.table, form = layui.form,laydate = layui.laydate;

            form.on('submit(demo1)', function(data){
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                var customer_level="";
                if(document.getElementsByClassName('rater-star-result')!=null){
                    $str=document.getElementsByClassName('rater-star-result')[0].innerText;
                    customer_level=$str.substr(0,1);
                }
                //console.log('2')
                data.field.customer_level=customer_level;

                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/admin/customer/{{$contacts->id}}" ,//url
                    data:data.field,
                    success: function (result) {
                        //window.location.reload();  //页面刷新
                        if(result['code']==0){
                            layer.msg('修改失败');
                        }
                        else{
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            layer.msg('修改成功');
                        }
                    },
                });
                //console.log($('.rater-star-result').innerText);
                return false;
            });
            //日期
            laydate.render({
                elem: '#date'
            });

            loadProvince();
            //加载省数据
            function loadProvince() {
                var proHtml = '';
                for (var i = 0; i < areaData.length; i++) {
                    proHtml += '<option value="' + areaData[i].provinceCode + '_' + areaData[i].mallCityList.length + '_' + i +'_' + areaData[i].provinceName+ '">' + areaData[i].provinceName + '</option>';
                }
                //初始化省数据
                $form.find('select[name=prov]').append(proHtml);
                form.render();
                form.on('select(prov)', function(data) {
                    $form.find('select[name=dist]').html('<option value="">请选择县/区</option>');
                    var value = data.value;
                    var d = value.split('_');
                    var code = d[0];
                    var count = d[1];
                    var index = d[2];
                    if (count > 0) {
                        loadCity(areaData[index].mallCityList);
                    } else {
                        $form.find('select[name=city]').attr("disabled","disabled");
                    }
                });
            }
            //加载市数据
            function loadCity(citys) {
                var cityHtml = '<option value="">请选择市</option>';
                for (var i = 0; i < citys.length; i++) {
                    cityHtml += '<option value="' + citys[i].cityCode + '_' + citys[i].mallAreaList.length + '_' + i +'_' + citys[i].cityName+ '">' + citys[i].cityName + '</option>';
                }
                $form.find('select[name=city]').html(cityHtml).removeAttr("disabled");
                form.render();
                form.on('select(city)', function(data) {
                    var value = data.value;
                    var d = value.split('_');
                    var code = d[0];
                    var count = d[1];
                    var index = d[2];
                    if (count > 0) {
                        loadArea(citys[index].mallAreaList);
                    } else {
                        $form.find('select[name=dist]').attr("disabled","disabled");
                    }
                });
            }
            //加载县/区数据
            function loadArea(areas) {
                var areaHtml = '<option value="">请选择县/区</option>';
                for (var i = 0; i < areas.length; i++) {
                    areaHtml += '<option value="' + areas[i].areaName + '">' + areas[i].areaName + '</option>';
                }
                $form.find('select[name=dist]').html(areaHtml).removeAttr("disabled");
                form.render();
                form.on('select(dist)', function(data) {
                    //console.log(data);
                });
            }
        });


    </script>

